<?php
/*
 * akimimi front
 *
 * My Query View
 *
 * @author by M.Wang
 *
 */
require_once '../app/views/BaseView.php';

class MyQueryView extends BaseView {

    public function getMyQueryPage($arr_param){
        $arr_navsetting = array(
            array('url'=>'/userinfo/index', 'text'=>MYAKIMIMITXT),
            array('text'=>MYQUERYTXT)
        );
        $this->setPageTitle(MYQUERYTXT);
        $this->addCSS('myaccount.css');
        $this->addCSS('myaccountleftnav.css');
        $header = '';
        require_once '../app/views/MyAccoutLeftNavView.php';
        $myAccountLeftNavView = new MyAccountLeftNav();
        $str_result = $header
                    . $this->getNavigation($arr_navsetting)
                    . "<div id='mymimi_body'>"
                    . $myAccountLeftNavView->getMyAccountLeftNav()
                    . $this->getContent($arr_param)
                    . '</div>';
        return $this->getHtmlPage($str_result);
    }

    public function getContent($arr_param) {
        return "<div id='mymimi_right'>"
               . "<div class='right_bj'></div>"
               . $this->getList($arr_param)
               . $this->getDetail($arr_param)
               . "</div>";
    }

    public function getList($arr_param){
        $str_outer = "<div class='zi_box'>"
                   . '<h5>' . MYQUERYTXT . '</h5>'
                   . "<table class='zi_table' cellpadding='0' cellspacing='0' border='0'>"
                   . '<tbody>%s</tbody>'
                   . "</table>"
                   . '</div>';
        if (empty($arr_param)) {
        	return sprintf($str_outer,'');
        }

        /**
         * @desc get list
         */
        $str_list = '';
        foreach ($arr_param['rows'] as $arr_data) {
        	$str_list.= '<tr>'
        	          . "<td class='zi_table_td1'>{$arr_data['query_id']}</td>"
        	          . "<td class='zi_table_td1'>{$arr_data['product_title']}</td>"
        	          . "<td class='zi_table_td1'>{$arr_data['query_type']}</td>"
        	          . "<td class='zi_table_td1'>{$arr_data['query_status']}</td>"
        	          . "<td class='zi_table_td1'>{$arr_data['query_created']}</td>"
        	          . "<td class='zi_table_td1'><a href='#query_detail_{$arr_data['query_id']}'>" . MQPREVIEWTXT . "</a></td>"
        	          . '</tr>';
        }
        $pager = new Pager();
        $str_list.= "<tr><td id='zi_tabletr1' colspan='6'><div class='p2_page'>" . $pager->paginate($arr_param['pager']['nowpage'], $arr_param['pager']['countrows'], '/userinfo/myquery/', $arr_param['pager']['prepage'] ) . "</div></td></tr>";

        return sprintf($str_outer, $str_list);

    }

    public function getDetail($arr_param) {
        $str_outer = "<div class='zi_box1'>"
                   . '<h5>' . SQDETAILTXT . '</h5>'
                   . '%s'
                   . "</div>";
        if (empty($arr_param['rows'])) {
        	return sprintf($str_outer,'');
        }
        $str_detail = '';
        foreach ($arr_param['rows'] as $arr_data) {
        	$str_detail.= "<ul>"
        	            . "<li class='zi_box1_li01'><a name='query_detail_{$arr_data['query_id']}'>{$arr_data['query_content']}</a></li>";
        	if (!empty($arr_data['reply_created'])) {
            	$str_detail.= "<li class='zi_box1_li02'>{$arr_data['reply_content']}</li>"
            	            . "<li class='zi_box1_li03'>" . sprintf(MIMISERVICEREPLYTXT, $arr_data['admin_name'], $arr_data['reply_created']) . "</li>";
        	}
        	$str_detail.= "</ul>";
        }
        return sprintf($str_outer,$str_detail);
    }

}
?>